package com.gecba.system.controller;

import com.gecba.system.entity.SysUser;
import com.gecba.system.service.SysUserService;
import com.gecba.system.util.PageUtil;
import com.gecba.system.vo.PageVO;
import com.gecba.system.vo.Result;
import com.gecba.system.vo.SearchVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 *
 *@author ChenBo
 *@date 2021/7/19
 */
@Api(tags = "系统用户")
@Slf4j
@RestController
@RequestMapping("/user")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;


    @ApiOperation(value = "多条件分页获取用户列表")
    @GetMapping(value = "/pageList")
    public Result<Page<SysUser>> pageList(SysUser sysUser, SearchVO searchVO,PageVO pageVO){
       Page<SysUser> page = sysUserService.findByCondition(sysUser,searchVO, PageUtil.initPage(pageVO));
       return Result.OK(page);
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加用户")
    public Result<?> save(@RequestBody SysUser sysUser){

        sysUserService.addUser(sysUser);
        return Result.OK();
    }

    @ApiOperation(value = "修改用用户")
    @PutMapping("/edit")
    public Result<?> edit(@RequestBody SysUser sysUser){
        sysUserService.updateUser(sysUser);
        return Result.OK();
    }

    @ApiOperation(value = "删除用户")
    @DeleteMapping("/delete")
    public Result<?> delete(@RequestParam(value = "id") Long id){
        sysUserService.delete(id);
        return Result.OK();
    }



}
